<?php
/**
 * Maker: 梁康宁
 * Time: 2019-09-18 11:37:51
*/
namespace app\dlc\controller;
use app\common\model\Article;
use app\dlc\common\helpers\ApiHelper;
use think\Db;
class PlanController extends CommonController
{
	public function index()
	{

	    $this->headBotton("","add","添加",CONTROLLER_URL . "_edit");
	    $this->headSearch("","name","计划名称","1");
	    $this->listBotton("","edit","编辑",CONTROLLER_URL . "_edit",0,"","","","");
        $this->listBotton('','enable','启用',CONTROLLER_URL . 'enable',1,'','','',['status','=','2']);
        $this->listBotton('','disable','禁用',CONTROLLER_URL . 'disable',1,'','','',['status','=','1']);
	    $this->listBotton("","del","删除",CONTROLLER_URL . "_del",0,"","","","");
		$this->loading();
		$map = $this->map();
		$data = model(CONTROLLER_NAME)->where($map)->order('id desc')->page(self::$page)->select();
		$count = model(CONTROLLER_NAME)->where($map)->count();
		$this->getPage($count, self::$psize, 'App-loader', $this->title, 'App-search');
		$this->assign('data',$data);
		$list = ["id"=>"ID","name"=>"计划名称","website|name"=>"所属网站","num"=>"每天总数量","period"=>"时间段",'statusText'=>'状态',"ctime"=>"创建时间",'sys'=>"操作"];
		$this->assign('list',$list);
		echo $this->fetch('common/index');
	}


	//$funName 添加和编辑成功后的回调方法,返回 $id,$action , $action =add 是添加，$action = edit 是编辑
    public function _edit($updata = false, $add = false, $noRepeat = false, $funName = false)
    {
//        $updata['table'] = "";//更新的表，默认自动获取
//        $updata['key'] = "";//表的主键，默认自动获取
//        $noRepeat['map'] = "";//新增判断条件
//        $noRepeat['name'] = "";//字段，不可重复的字段
//        $noRepeat['tig'] = "";//提示语
        parent::_edit($updata, $add, $noRepeat, $funName);
    }

    public function _del($tabelName = false, $tableKey = 'id', $child = false, $delChild = false)
    {
//        $child['tableName'] = '';//下级表，如果这个是分类表，使用该分类的表   如:goods 是goods_type的下级
//        $child['key'] = '';//外键 如：goods_type_id
//        $child['msg'] = '该分类下有数据，不能删除';//提示语
//        $delChild['tableName'] = '';///下级表，如果这个是分类表，使用该分类的表，删除该分类的数据 如:goods 是goods_type的下级
//        $delChild['key'] = '';//外键 如：goods_type_id
        //$child = ['tableName'=>'shop','key'=>'agent_id','msg'=>'该分类下有数据，不能删除'];
        parent::_del($tabelName, $tableKey, $child, $delChild);
    }

    //测试
   public function test(){
	    $id = [2921];
	    $artile = Article::get($id);
	    $baseUrl = $artile['website']['url'];
        ApiHelper::sendArticle('http://kang.batterywd.com/',$id);
//        $res = Db::name('article')->where(['status'=>2])->column('id');

    }

}
?>